/**
 * 格式化日期时间为字符串
 * @param dateString - ISO 格式日期字符串
 * @returns 格式化后的日期时间字符串，例如：2024-11-20 12:03:07
 */
export const formatDateTime = (dateString: string): string => {
  const date = new Date(dateString)
  const pad = (num: number) => num.toString().padStart(2, '0')
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}

// 格式化 ISO8601 日期字符串
export const formatISO8601 = (date: Date): string => {
  const pad = (n: number): string => String(n).padStart(2, '0')
  const year = date.getUTCFullYear()
  const month = pad(date.getUTCMonth() + 1)
  const day = pad(date.getUTCDate())
  const hours = pad(date.getUTCHours())
  const minutes = pad(date.getUTCMinutes())
  const seconds = pad(date.getUTCSeconds())
  const milliseconds = String(date.getUTCMilliseconds()).padStart(3, '0')
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}+00:00`
}

// 格式化价格
export const formatPrice = (price: number | string) => {
    const numericPrice = parseFloat(price as string)
    if (numericPrice > 9999) {
      return (Math.floor((numericPrice / 10000) * 100) / 100).toFixed(2) + '万'
    }
    return numericPrice.toString()
  }

